import 'package:flutter/material.dart';

/// 结果背景提示
class ResultNotice extends StatefulWidget {
  final Color color;
  final String info;

  const ResultNotice({super.key, required this.color, required this.info});

  @override
  State<ResultNotice> createState() => _ResultNoticeState();
}

class _ResultNoticeState extends State<ResultNotice>
    with SingleTickerProviderStateMixin {
  late AnimationController controller;

  @override
  void initState() {
    super.initState();
    // 创建动画控制器
    controller = AnimationController(
        vsync: this, duration: const Duration(milliseconds: 200));
    // 启动动画器
    controller.forward();
  }

  /// 当上级状态触发 setState 时，会触发子级的 didUpdateWidget 回调
  @override
  void didUpdateWidget(covariant ResultNotice oldWidget) {
    controller.forward(from: 0);
    super.didUpdateWidget(oldWidget);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
        child: Container(
            alignment: Alignment.center,
            color: widget.color,
            child: AnimatedBuilder(
              animation: controller,
              builder: (_, child) => Text(
                widget.info,
                style: TextStyle(
                    fontSize: 54 * (controller.value),
                    color: Colors.white,
                    fontWeight: FontWeight.bold),
              ),
            )));
  }
}
